/*
 * Potion.cpp
 *
 *  Created on: Oct 19, 2011
 *	Created by: Devin Manno
 *  Updated by: Devin Manno
 *	Last Update: Oct 19, 2011
 */

#include "Potion.h"
#include "Utility.h"
// potion
// Randomly generates a potion that refills health, action
//	points, or both
// Pre: none
// Post: a new potion is created
// Returns: none (constructor)
Potion::Potion() : Base("Potion") {
	
	int value = Utility::getSeed(7);

    createPotion(value);
}

Potion::Potion(potionType potionTypeToCreate) : Base("Potion") {
    
    createPotion(potionTypeToCreate);
}

void Potion::createPotion(int potionTypeToCreate) {
    
    switch (potionTypeToCreate) {
        case 0:
            setDesc("Minor Health Potion");
            hitPointPercentage = 0.25;
            actionPointPercentage = 0;
            break;
        case 1:
            setDesc("Medium Health Potion");
            hitPointPercentage = 0.5;
            actionPointPercentage = 0;
            break;
        case 2:
            setDesc("Strong Health Potion");
            hitPointPercentage = .75;
            actionPointPercentage = 0;
            break;
        case 3:
            setDesc("Minor Action Potion");
            hitPointPercentage = 0;
            actionPointPercentage = 0.25;
            break;
        case 4:
            setDesc("Medium Action Potion");
            hitPointPercentage = 0;
            actionPointPercentage = 0.5;
            break;
        case 5:
            setDesc("Strong Action Potion");
            hitPointPercentage = 0;
            actionPointPercentage = 0.75;
            break;
        case 6:
            setDesc("Fortification Potion");
            hitPointPercentage = 0.55;
            actionPointPercentage = 0.55;
            break;
        default: // shouldn't happen
            setDesc("Oddidy Potion");
            hitPointPercentage = 0;
            actionPointPercentage = 0;
            break;
	}

}
Potion::~Potion() {
	// TODO Auto-generated destructor stub
}

// getters
float Potion::getHitPointPercentage(){
	return hitPointPercentage;
}

float Potion::getActionPointPercentage(){
	return actionPointPercentage;
}

ostream& operator<<(ostream& out, Potion &p)
{
    out << p.getObjectID() << ',' << p.getDesc() << ',' << p.hitPointPercentage << ',' << p.actionPointPercentage;
    return out;
}

istream& operator>>(istream& in, Potion &p)
{
    char *tk = NULL;// pointers to chars
    char data[MAX] = ""; //to hold line
    in.getline(data,MAX - 1, '\n');
    tk = strtok(data, DELIMS);  //get first token of new line
    p.setObjectID(atoi(tk));
    tk = strtok(NULL, DELIMS); // get next token
    p.setDesc(tk);
    tk = strtok(NULL, DELIMS); // get next token
    p.hitPointPercentage = atof(tk);
    tk = strtok(NULL, DELIMS); // get next token
    p.actionPointPercentage = atof(tk);
    return in;
}
